package cn.shop.thiredparty.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import eu.medsea.mimeutil.MimeUtil2;
import eu.medsea.mimeutil.detector.ExtensionMimeDetector;
import eu.medsea.mimeutil.detector.MagicMimeMimeDetector;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : 李一涵
 * @date : Created in 2022/5/18 11:23
 * @description :
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "oss")
public class OSSConfig {

    private String endpoint;
    private String key;
    private String secret;
    private String bucketName;
    private String prefix;

    @Bean(destroyMethod = "shutdown")
    public OSS oSSClient() {
        OSSClientBuilder builder = new OSSClientBuilder();
        return builder.build(endpoint, key, secret);
    }

    @Bean
    public MimeUtil2 mimeUtil() {
        MimeUtil2 mimeUtil = new MimeUtil2();
        mimeUtil.registerMimeDetector(ExtensionMimeDetector.class.getName());
        mimeUtil.registerMimeDetector(MagicMimeMimeDetector.class.getName());
        return mimeUtil;
    }

}
